#!/usr/bin/env bash

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

dump() {
  SRC=`realpath $1`

  G=$2
  F=`basename ${SRC} .py`

  OUT_DIR=${SCRIPT_DIR}/output/${F}-${G}

  mkdir -p ${OUT_DIR}
  rm -rf ${OUT_DIR}/*

  echo "Compile ..." `realpath ${SRC}` "with ${G}"
  LOG=${OUT_DIR}/log.mlir
  echo "Compile Log" `realpath ${LOG}`
  GPU=${G} OUTPUT=${OUT_DIR} python3 ${SRC} > ${LOG} 2>&1
  RES=$?
  MSG="Err"
  if (( ${RES} == 0 )); then
    MSG="Ack"
  fi
  echo "Compile ${MSG}" `realpath ${SRC}` "with ${G}"
}

SRCS=(
  01-vector-add.py
  02-fused-softmax.py
  03-matrix-multiplication.py
  04-low-memory-dropout.py
  05-layer-norm.py
  06-fused-attention.py
  08-grouped-gemm.py
  09-persistent-matmul.py
  10-block-scaled-matmul.py
  triton_unk_fused_sum_1.py
  triton_unk_fused_mul_sum_3.py
)

GPUS=(
  blackwell
  hopper
  ampere
  # TODO
  # hip_rdna3
  # hip_rdna4
  # hip_cdna3
  # hip_cdna4
)

for SRC in "${SRCS[@]}"; do
  for GPU in "${GPUS[@]}"; do
    dump ${SRC} ${GPU}
  done
done

